package ui.data
{
	import flash.display.Sprite;

	public class ScrollPanel extends Sprite
	{
		private var maskRow:Sprite;
		private var row:PanelRow;
		private var numRows:Number;
		private var rows:Array;
		
		public function ScrollPanel() {
			maskRow = new Sprite();
			rows = new Array();
		}
		
		public function addRow(value:PanelRow):void {
			if (rows.length > 0) {
				value.y = (rows[rows.length - 1] as PanelRow).y + row.height - 1;
			} else {
				value.y = 0;
			}
			
			value.draw();
			rows.push(value);
			
			addChild(value);
		}
		
		public function setPanelRow(sample:PanelRow):void {
			this.row = sample;
			if (numRows > 0) {
				createMask();
			}
		}
		
		public function setNumberOfRows(num:Number):void {
			this.numRows = num;
			if (row != null) {
				createMask();
			}
		}
		
		private function createMask():void {
			var maskHeight:Number = numRows * row.height;
			maskRow.graphics.beginFill(1, 1);
			maskRow.graphics.drawRoundRect(0, 0, row.width, maskHeight - numRows + 1, 30, 30);
			maskRow.graphics.endFill();
			addChild(maskRow);
			this.mask = maskRow;
		}
	}
}